package cn.com.ctcloud.saas.core.config;

import java.io.IOException;
import java.util.Properties;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.stereotype.Component;

/**
 * Title: ChinaCT IDS
 * <p>
 * Description: 自定义一个工具类，来获取application.properties信息
 * <p>
 * Copyright: Copyright (c) 2008
 * <p>
 * Company: Liaoning Open Data Communication Co.,Ltd.
 *
 * @author lihui
 * @version 2.0.0
 */
@Component
public class SystemConfig {
	private static Properties props;

	public SystemConfig() {
		try {
			final Resource resource = new ClassPathResource("/application.properties");
			SystemConfig.props = PropertiesLoaderUtils.loadProperties(resource);
		} catch (final IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取属性
	 *
	 * @param key
	 * @return
	 */
	public static String getProperty(final String key) {
		return SystemConfig.props == null ? null : SystemConfig.props.getProperty(key);
	}

	/**
	 * 获取属性
	 *
	 * @param key
	 *            属性key
	 * @param defaultValue
	 *            属性value
	 * @return
	 */
	public static String getProperty(final String key, final String defaultValue) {
		return SystemConfig.props == null ? null : SystemConfig.props.getProperty(key, defaultValue);
	}

	/**
	 * 获取properyies属性
	 *
	 * @return
	 */
	public static Properties getProperties() {
		return SystemConfig.props;
	}
}
